package cn.edu.scau.cmi.houzhicong.client;

import cn.edu.scau.cmi.houzhicong.singletonPattern.domain.MultiChairMan;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class MultiChairManClient extends Application{

	private int accout = 1;
	private Text text = new Text("未输入ID");
	private TextField textField = new TextField();
	@Override
	public void start(Stage primaryStage) {
		try {
			Pane vBox = new VBox();
			Button addButton = new Button("获取毛主席");
			addButton.setOnAction(e->{
				MultiChairMan multiChairMan = MultiChairMan.addMultiChairMan(textField.getText());
				if(multiChairMan!=null){
					text.setText("共新建了"+accout++ +"次毛主席,其ID为"+ multiChairMan.getId());
				}else{
					text.setText("新建次数已超过容纳量！");
				}

			});

			textField.setPrefSize(100,30);
			addButton.setPrefSize(100,30);
			vBox.getChildren().add(textField);
			vBox.getChildren().add(addButton);
			vBox.getChildren().add(text);

			Scene scene = new Scene(vBox,250,100);
			primaryStage.setScene(scene);
			primaryStage.show();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		launch(args);
	}
}
